//
//  MyTabBar.m
//  TravelFollowYourHeart
//
//  Created by 鲁万玺 on 2017/12/7.
//  Copyright © 2017年 Lwx. All rights reserved.
//

#import "MyTabBar.h"

#import "MyTabBar.h"

@interface MyTabBar ()

@property (nonatomic,strong) UIView *bgView;

@end

@implementation MyTabBar

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.bgView = [UIView new];
        self.bgView.backgroundColor = [UIColor clearColor];
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 4;
        self.bgView.size = CGSizeMake(40, 40);
//        self.layer.shadowColor = [UIColor blackColor].CGColor;
//        self.layer.shadowRadius= 4;
//        self.layer.shadowOpacity = .5;
        [self addSubview:self.bgView];
        
        UIButton *plusBtn = [[UIButton alloc] init];
        plusBtn.backgroundColor = [UIColor clearColor];
        [plusBtn setImage:[UIImage imageNamed:@"tab_xc"] forState:UIControlStateNormal];
        [plusBtn setImage:[UIImage imageNamed:@"tab_xc"] forState:UIControlStateSelected];
        plusBtn.size = CGSizeMake(40, 40);
        plusBtn.userInteractionEnabled = NO;
        [self addSubview:plusBtn];
        self.plusBtn = plusBtn;
        
        UILabel *titleLabel = [UILabel new];
        titleLabel.text = @"定制";
        titleLabel.font = DEF_FontSize_10;
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.textColor = [UIColor colorWithHex:0x808080];
        [self addSubview:titleLabel];
        self.titleLabel = titleLabel;
        
        CGRect rect = CGRectMake(0, 0, SCREEN_WIDTH, 1);
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
        CGContextFillRect(context, rect);
        UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        
        self.barTintColor = [UIColor whiteColor];
        self.translucent = NO;
        self.shadowImage = img;
        [self setBackgroundImage:img];
        [self setShadowImage:img];
    }
    return self;
}



/**
 *  想要重新排布系统控件subview的布局，推荐重写layoutSubviews，在调用父类布局后重新排布。
 */
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // 1.设置加号按钮的位置
    self.plusBtn.centerX = self.width*0.5;
    self.plusBtn.centerY = self.height*0.20;
    self.bgView.centerX = self.width*0.5;
    self.bgView.centerY = self.height*0.25;
    
    self.titleLabel.frame = CGRectMake(CGRectGetMinX(self.plusBtn.frame)-20, 49-18, self.plusBtn.frame.size.width+40, 18);
    
}

@end

